package org.hs.phd.odi.tracking.performanceevaluation;

import java.awt.Polygon;
import java.awt.Rectangle;

import org.hs.phd.common.simpleplayer.ImageSequenceFrame;

public class SpatialOverlappingPercentageMetric extends AbstractTrackingPerformanceMetric {

	@Override
	protected float compute(ImageSequenceFrame frame, Polygon groundTruthTrackShape, Polygon computedTrackShape) {
		Rectangle gtBoundingBox = groundTruthTrackShape.getBounds();
		Rectangle compBoundingBox = computedTrackShape.getBounds();
		Rectangle overlap = gtBoundingBox.intersection(compBoundingBox);

		float overlapArea = gtBoundingBox.intersects(compBoundingBox) ? overlap.width*overlap.height : 0;
		float gtArea = gtBoundingBox.width*gtBoundingBox.height;
		
		return 100*overlapArea/gtArea;
	}

	@Override
	public String getShortName() {
		return "Spat.Ovr.%";
	}

	@Override
	public String getName() {
		return "Spatial Overlapping";
	}

	@Override
	public String getUnitName() {
		return "Percentage";
	}

	@Override
	public float getRangeMin() {
		return 0;
	}

	@Override
	public float getRangeMax() {
		return 100;
	}

}
